package com.redstar.HappyRefresh.pojo;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {

    private int code; // 响应码

    private Boolean state; // 返回状态

    private String message; // 返回信息

    private Object data; // 返回数据

    private long count; // 分页查询总记录数

    // 成功
    public static Result succeed(){
        Result result = new Result();
        result.setCode(0);
        result.setState(true);
        result.setMessage("成功");
        return result;
    }

    // 失败
    public static Result fail(){
        Result r = new Result();
        r.setCode(201);
        r.setState(false);
        r.setMessage("失败");
        return r;
    }

    public Result code(int code){
        this.setCode(code);
        return this;
    }

    public Result state(Boolean state){
        this.setState(state);
        return this;
    }

    public Result message(String message){
        this.setMessage(message);
        return this;
    }

    public Result data(Object result){
        this.setData(result);
        return this;
    }

    public Result count(long count){
        this.setCount(count);
        return this;
    }
}
